package com.property.manage.controller.resource;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.resource.Building;
import com.property.manage.model.resource.BuildingVo;
import com.property.manage.service.resource.BuildingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "樓棟管理")
@RestController
@RequestMapping("/building")
@AllArgsConstructor
@Validated
public class BuildingController {

    private BuildingService buildingService;


    @ApiOperation("楼栋列表")
    @GetMapping("/page")
    public CustomPage<BuildingVo> userPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                           @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                           @ApiParam("小区编号") @RequestParam(value = "villageId", required = false) Integer villageId,
                                           @ApiParam("楼栋") @RequestParam(value = "building", required = false) Integer building,
                                           @ApiParam("单元") @RequestParam(value = "unit", required = false) Integer unit,
                                           @ApiParam("房号") @RequestParam(value = "roomNumber", required = false) String roomNumber){
        return buildingService.buildingPage(pageNo, pageSize,villageId,building,unit,roomNumber);
    }

    @ApiOperation("添加樓棟信息")
    @PostMapping("/add")
    public void add(@RequestParam(value ="villageId" ) @NotNull(message = "小区id不能为空")Integer villageId,
                    @RequestParam(value = "building")    @NotNull(message = "楼栋不能为空") Integer building,
                    @RequestParam(value ="status" )@NotNull(message = "状态不能为空")Integer status,
                    @RequestParam(value ="unit" )@NotNull(message = "单元不能为空")Integer unit,
                    @RequestParam(value = "roomNumber") @NotNull(message = "房号不能为空")String roomNumber,
                    @RequestParam(value = "square")@NotNull(message = "面积不能为空") BigDecimal square,
                    @ApiParam("折扣")  @RequestParam(value = "discount")@NotBlank(message = "物业折扣不能为空") String discount){
        buildingService.add(villageId,building,status,unit,roomNumber,square,discount);
    }

    @ApiOperation("修改樓棟信息")
    @PostMapping("/update")
    public void update(@RequestParam(value ="id" ) @NotNull(message = "id不能为空")Integer id,
                       @RequestParam(value ="villageId" ) @NotNull(message = "小区id不能为空")Integer villageId,
                       @RequestParam(value = "building")    @NotNull(message = "楼栋不能为空") Integer building,
                       @RequestParam(value ="status" )@NotNull(message = "状态不能为空")Integer status,
                       @RequestParam(value ="unit" )@NotNull(message = "单元不能为空")Integer unit,
                       @RequestParam(value = "roomNumber") @NotNull(message = "房号不能为空")String roomNumber,
                       @RequestParam(value = "square")@NotNull(message = "面积不能为空") BigDecimal square,
                       @RequestParam(value = "discount")@NotNull(message = "物业折扣不能为空") String discount){
        buildingService.update(id,villageId,building,status,unit,roomNumber,square,discount);
    }

    @ApiOperation("删除樓棟信息")
    @PostMapping("/delete")
    public void delete(@ApiParam("小区id") @RequestParam("id") @NotNull(message = "小区id为空") Integer id){
        buildingService.delete(id);
    }
    @ApiOperation("单条楼栋信息")
    @GetMapping("/findOneByBuildingId")
    public Building findOne(@ApiParam("小区编号") @RequestParam(value = "villageId", required = false) Integer villageId,
                            @ApiParam("楼栋") @RequestParam(value = "building", required = false) Integer building,
                            @ApiParam("单元") @RequestParam(value = "unit", required = false) Integer unit,
                            @ApiParam("房号") @RequestParam(value = "roomNumber", required = false) String roomNumber){
        return buildingService.findOne(villageId,building,unit,roomNumber);
    }
}
